package com.demo.function.spring.interceptor.config;

import com.demo.function.spring.interceptor.Interceptor1;
import com.demo.function.spring.interceptor.Interceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private Interceptor1 interceptor1;

    /**
     * 注意：这里拦截器实例化有两种方式
     * 第一种：由Spring管理，拦截器由Spring实例化为一个Beean
     * 第二种，直接通过关键字new创建拦截器对象
     *
     * 由Spring创建的拦截器可以自动依赖注入其他Bean，非Spring管理则不行
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor1).addPathPatterns("/filterAndInnterceptor/process/order");
        registry.addInterceptor(new Interceptor2()).addPathPatterns("/filterAndInnterceptor/process/order");
    }
}
